package ai.zixing.example01;

import java.util.ArrayList;
import java.util.List;

/**
 * 具体目标类
 */
public class ConcreteSubject implements Subject{

    private List<Observer> observers = new ArrayList<>();

    //注册方法,向观察者集合中增加一个观察者
    @Override
    public void attach(Observer observer) {
        observers.add(observer);
    }

    // 移除
    @Override
    public void detach(Observer observer) {
        observers.remove(observer);
    }

    // 通知
    @Override
    public void notifyObservers() {
        for (Observer observer : observers) {
            observer.update();
        }
    }
}
